package com.ittest.dao;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ittest.domain.Book;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class BookDaoTestCase {


    @Autowired
    private BookDao bookDao;


    @Test
    void testGetById() {

        System.out.println(bookDao.selectById(1));
    }
    @Test
    void testSave() {

        Book book = new Book();
        book.setName("青春环游记");
        book.setType("青春");
        book.setDescription("这是一本讲述青春与冒险的故事");

        bookDao.insert(book);
    }
    @Test
    void testUpdate() {
        Book book = new Book();
        book.setId(1);
        book.setName("哥只是一个传说");
        book.setType("青春");
        book.setDescription("请你不要在迷恋哥，哥只是一个传说");
        bookDao.updateById(book);
    }
    @Test
    void testDelete() {

        bookDao.deleteById(22);
    }

    @Test
    void testGetall() {

        System.out.println(bookDao.selectList(null));
    }

    @Test
    void testGetPage() {
        IPage page = new Page(2,5);
        IPage Page = bookDao.selectPage(page, null);
        System.out.println(Page.getPages());
        System.out.println(Page.getRecords());
        System.out.println(Page.getSize());
        System.out.println(Page.getTotal());
        System.out.println(Page.getCurrent());

    }
    @Test
    void testGetBy() {
        QueryWrapper<Book> qf = new QueryWrapper<>();
        qf.like("name","三");

        bookDao.selectList(qf);
    }

    @Test
    void testGetBy2() {
        String name = "三";
        LambdaQueryWrapper<Book> lqf = new LambdaQueryWrapper<>();
        //if (name != null )
        lqf.like(name!= null,Book::getName,name);

        bookDao.selectList(lqf);
    }

}
